package cn.class2.demo2

/**
  * Created by lzd on 2018/11/9.
  */
class Demo2(val id: Long, val name: String = "tom", var age: Int) {
  var gender: String = _

  //构造器不可用val或var
  def this(id: Long, name: String, age: Int, gender: String) {
    //辅助构造器第一行必须先调用主构造器
    this(id, name, age)
    this.gender = gender
  }

  def this() {
    this(12, "hello", 12)
  }

}

object Demo2 {
  def main(args: Array[String]): Unit = {
    val d1 = new Demo2(12,"jetty",13)
    println(d1.id)
    println(d1.name)
    println(d1.age)
    println("**" * 10)
    val d2 = new Demo2(12,"jetty",13,"man")
    println(d2.id)
    println(d2.name)
    println(d2.age)
    println(d2.gender)
    println("**" * 10)
    val d3 = new Demo2()
    println(d3.id)
    println(d3.name)
    println(d3.age)
    println(d3.gender)
  }
}

object Other{
  def main(args: Array[String]): Unit = {
    val d1 = new Demo2(12,"jetty",13)
    println(d1.id)
    println(d1.name)
    println(d1.age)
    println("**" * 10)
    val d2 = new Demo2(12,"jetty",13,"man")
    println(d2.id)
    println(d2.name)
    println(d2.age)
    println(d2.gender)
    println("**" * 10)
    val d3 = new Demo2()
    println(d3.id)
    println(d3.name)
    println(d3.age)
    println(d3.gender)
  }
}